<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('修改党员信息')" />
	<th:block th:include="include :: select2-css" />
	<style>
		.form-group .control-label {
			font-weight: bold;
		}
		.upload-area {
			border: 2px dashed #ccc;
			border-radius: 4px;
			padding: 20px;
			text-align: center;
			cursor: pointer;
			transition: all 0.3s;
		}
		.upload-area:hover {
			border-color: #c52222;
			background-color: #f9f9f9;
		}
		.upload-area i {
			font-size: 48px;
			color: #c52222;
			margin-bottom: 10px;
		}
		.file-info {
			margin-top: 10px;
			font-size: 14px;
			color: #666;
		}
	</style>
</head>
<body class="gray-bg">
	
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>修改党员信息</h5>
					</div>
					<div class="ibox-content">
						<form class="form-horizontal m" id="form-member-edit" th:object="${partyMember}" enctype="multipart/form-data">
							<input name="id" th:field="*{id}" type="hidden">
							<div class="form-group">
								<label class="col-sm-3 control-label">关联用户：</label>
								<div class="col-sm-8">
									<select name="userId" class="form-control" required>
										<option value="">请选择用户</option>
										<option th:each="user : ${users}" th:value="${user.userId}" th:text="${user.userName}+'('+${user.loginName}+')'" th:selected="${user.userId == partyMember.userId}"></option>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">所属党支部：</label>
								<div class="col-sm-8">
									<select name="deptId" class="form-control" required>
										<option value="">请选择党支部</option>
										<option th:each="dept : ${depts}" th:value="${dept.deptId}" th:text="${dept.deptName}" th:selected="${dept.deptId == partyMember.deptId}"></option>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">党员编号：</label>
								<div class="col-sm-8">
									<input name="partyNo" th:field="*{partyNo}" class="form-control" type="text" required>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">姓名：</label>
								<div class="col-sm-8">
									<input name="name" th:field="*{name}" class="form-control" type="text" required>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">性别：</label>
								<div class="col-sm-8">
									<select name="gender" th:field="*{gender}" class="form-control" required>
										<option value="0">男</option>
										<option value="1">女</option>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">出生日期：</label>
								<div class="col-sm-8">
									<input name="birthDate" th:field="*{birthDate}" class="form-control" type="date">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">民族：</label>
								<div class="col-sm-8">
									<select name="nation" th:field="*{nation}" class="form-control">
										<option value="">请选择民族</option>
										<option value="汉族">汉族</option>
										<option value="壮族">壮族</option>
										<option value="满族">满族</option>
										<option value="回族">回族</option>
										<option value="苗族">苗族</option>
										<option value="维吾尔族">维吾尔族</option>
										<option value="土家族">土家族</option>
										<option value="彝族">彝族</option>
										<option value="蒙古族">蒙古族</option>
										<option value="藏族">藏族</option>
										<option value="布依族">布依族</option>
										<option value="侗族">侗族</option>
										<option value="瑶族">瑶族</option>
										<option value="朝鲜族">朝鲜族</option>
										<option value="白族">白族</option>
										<option value="哈尼族">哈尼族</option>
										<option value="哈萨克族">哈萨克族</option>
										<option value="黎族">黎族</option>
										<option value="傣族">傣族</option>
										<option value="畲族">畲族</option>
										<option value="傈僳族">傈僳族</option>
										<option value="仡佬族">仡佬族</option>
										<option value="东乡族">东乡族</option>
										<option value="高山族">高山族</option>
										<option value="拉祜族">拉祜族</option>
										<option value="水族">水族</option>
										<option value="佤族">佤族</option>
										<option value="纳西族">纳西族</option>
										<option value="羌族">羌族</option>
										<option value="土族">土族</option>
										<option value="仫佬族">仫佬族</option>
										<option value="锡伯族">锡伯族</option>
										<option value="柯尔克孜族">柯尔克孜族</option>
										<option value="达斡尔族">达斡尔族</option>
										<option value="景颇族">景颇族</option>
										<option value="毛南族">毛南族</option>
										<option value="撒拉族">撒拉族</option>
										<option value="布朗族">布朗族</option>
										<option value="塔吉克族">塔吉克族</option>
										<option value="阿昌族">阿昌族</option>
										<option value="普米族">普米族</option>
										<option value="鄂温克族">鄂温克族</option>
										<option value="怒族">怒族</option>
										<option value="京族">京族</option>
										<option value="基诺族">基诺族</option>
										<option value="德昂族">德昂族</option>
										<option value="保安族">保安族</option>
										<option value="俄罗斯族">俄罗斯族</option>
										<option value="裕固族">裕固族</option>
										<option value="乌孜别克族">乌孜别克族</option>
										<option value="门巴族">门巴族</option>
										<option value="鄂伦春族">鄂伦春族</option>
										<option value="独龙族">独龙族</option>
										<option value="塔塔尔族">塔塔尔族</option>
										<option value="赫哲族">赫哲族</option>
										<option value="珞巴族">珞巴族</option>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">籍贯：</label>
								<div class="col-sm-8">
									<select name="nativePlace" th:field="*{nativePlace}" class="form-control">
										<option value="">请选择籍贯</option>
										<option value="北京市">北京市</option>
										<option value="天津市">天津市</option>
										<option value="河北省">河北省</option>
										<option value="山西省">山西省</option>
										<option value="内蒙古自治区">内蒙古自治区</option>
										<option value="辽宁省">辽宁省</option>
										<option value="吉林省">吉林省</option>
										<option value="黑龙江省">黑龙江省</option>
										<option value="上海市">上海市</option>
										<option value="江苏省">江苏省</option>
										<option value="浙江省">浙江省</option>
										<option value="安徽省">安徽省</option>
										<option value="福建省">福建省</option>
										<option value="江西省">江西省</option>
										<option value="山东省">山东省</option>
										<option value="河南省">河南省</option>
										<option value="湖北省">湖北省</option>
										<option value="湖南省">湖南省</option>
										<option value="广东省">广东省</option>
										<option value="广西壮族自治区">广西壮族自治区</option>
										<option value="海南省">海南省</option>
										<option value="重庆市">重庆市</option>
										<option value="四川省">四川省</option>
										<option value="贵州省">贵州省</option>
										<option value="云南省">云南省</option>
										<option value="西藏自治区">西藏自治区</option>
										<option value="陕西省">陕西省</option>
										<option value="甘肃省">甘肃省</option>
										<option value="青海省">青海省</option>
										<option value="宁夏回族自治区">宁夏回族自治区</option>
										<option value="新疆维吾尔自治区">新疆维吾尔自治区</option>
										<option value="台湾省">台湾省</option>
										<option value="香港特别行政区">香港特别行政区</option>
										<option value="澳门特别行政区">澳门特别行政区</option>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">政治面貌：</label>
								<div class="col-sm-8">
									<select name="politicalStatus" th:field="*{politicalStatus}" class="form-control" required>
										<option value="中共党员">中共党员</option>
										<option value="预备党员">预备党员</option>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">入党日期：</label>
								<div class="col-sm-8">
									<input name="joinPartyDate" th:field="*{joinPartyDate}" class="form-control" type="date" required>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">转正日期：</label>
								<div class="col-sm-8">
									<input name="conversionDate" th:field="*{conversionDate}" class="form-control" type="date">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">所属班级（学生党员）：</label>
								<div class="col-sm-8">
									<input name="classId" th:field="*{classId}" class="form-control" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">身份类型：</label>
								<div class="col-sm-8">
									<select name="identityType" th:field="*{identityType}" class="form-control" required>
										<option value="1">教师</option>
										<option value="2">学生</option>
										<option value="3">职工</option>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">党内职务：</label>
								<div class="col-sm-8">
									<select name="partyPost" th:field="*{partyPost}" class="form-control">
										<option value="">请选择党内职务</option>
										<option th:each="post : ${posts}" th:value="${post.postName}" th:text="${post.postName}" th:selected="${post.postName == partyMember.partyPost}"></option>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">联系电话：</label>
								<div class="col-sm-8">
									<input name="contactPhone" th:field="*{contactPhone}" class="form-control" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">邮箱：</label>
								<div class="col-sm-8">
									<input name="email" th:field="*{email}" class="form-control" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">入党申请书：</label>
								<div class="col-sm-8">
									<div class="upload-area" id="application-upload-area">
										<i class="fa fa-file-pdf-o"></i>
										<div>点击选择或拖拽文件到此处上传</div>
										<div class="file-info">支持PDF、DOC、DOCX格式文件</div>
									</div>
									<input type="file" id="applicationFile" name="applicationFile" accept=".pdf,.doc,.docx" style="display: none;">
									<input type="hidden" name="applicationPath" id="applicationPath" th:value="*{applicationPath}">
									<div id="application-file-name" class="file-info" style="display: none;"></div>
									<div th:if="${partyMember.applicationPath != null and partyMember.applicationPath != ''}">
										已上传：<a th:href="@{${partyMember.applicationPath}}" target="_blank">查看文件</a>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">状态：</label>
								<div class="col-sm-8">
									<select name="status" th:field="*{status}" class="form-control" required>
										<option value="0">正常</option>
										<option value="1">转出</option>
										<option value="2">休学</option>
										<option value="3">退休</option>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">是否是优秀党员：</label>
								<div class="col-sm-8">
									<select name="isExcellent" th:field="*{isExcellent}" class="form-control">
										<option value="0">否</option>
										<option value="1">是</option>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">备注：</label>
								<div class="col-sm-8">
									<textarea name="remark" th:field="*{remark}" class="form-control"></textarea>
								</div>
							</div>
							<div class="form-group">
								<div class="form-control-static col-sm-offset-9">
									<button type="submit" class="btn btn-primary">提交</button>
									<button type="button" class="btn btn-danger" onclick="closeItem()">关闭</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: select2-js" />
	<script type="text/javascript">
		var prefix = ctx + "system/partymember/member";
	
		// 入党申请书上传区域点击事件
		$('#application-upload-area').click(function() {
			$('#applicationFile').click();
		});
		
		// 入党申请书文件选择事件
		$('#applicationFile').change(function() {
			var file = this.files[0];
			if (file) {
				$('#application-file-name').text('已选择文件: ' + file.name).show();
				// 上传文件
				uploadFile(file, 'applicationPath');
			}
		});
		
		// 上传文件函数
		function uploadFile(file, targetId) {
			var formData = new FormData();
			formData.append("file", file);
			
			$.ajax({
				url: prefix + "/upload",
				type: "POST",
				data: formData,
				cache: false,
				contentType: false,
				processData: false,
				dataType: "json",
				success: function(result) {
					if (result.code == web_status.SUCCESS) {
						$("#" + targetId).val(result.fileName);
						$.modal.msgSuccess("文件上传成功");
					} else {
						$.modal.msgError("文件上传失败：" + result.msg);
					}
				},
				error: function() {
					$.modal.msgError("文件上传异常");
				}
			});
		}
		
		$("#form-member-edit").validate({
			onkeyup: false,
			rules:{
				userId:{
					required:true,
				},
				deptId:{
					required:true,
				},
				partyNo:{
					required:true,
					remote: {
		                url: prefix + "/checkPartyNoUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"id": function() {
		                        return $("#id").val();
		                    },
		                	"partyNo": function() {
		                        return $.common.trim($("#partyNo").val());
		                    }
		                }
		            }
				},
				name:{
					required:true,
				},
				gender:{
					required:true,
				},
				politicalStatus:{
					required:true,
				},
				joinPartyDate:{
					required:true,
				},
				identityType:{
					required:true,
				},
				status:{
					required:true,
				},
				applicationFile: {
                    extension: "pdf,doc,docx"
                }
			},
			messages: {
		        "partyNo": {
		            remote: "党员编号已经存在"
		        },
		        applicationFile: {
                    extension: "请输入有效的文件格式(.pdf,.doc,.docx)"
                }
		    },
		    focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	// 检查是否已上传文件
	        	var applicationPath = $("#applicationPath").val();
	        	if ($("#applicationFile")[0].files.length > 0 && !applicationPath) {
	        		$.modal.msgError("文件正在上传中，请稍候提交");
	        		return;
	        	}
	        	
	        	// 收集表单数据
	        	var data = {
	        		"id": $("input[name='id']").val(),
	        		"userId": $("select[name='userId']").val(),
	        		"deptId": $("select[name='deptId']").val(),
	        		"partyNo": $("input[name='partyNo']").val(),
	        		"name": $("input[name='name']").val(),
	        		"gender": $("select[name='gender']").val(),
	        		"birthDate": $("input[name='birthDate']").val(),
	        		"nation": $("select[name='nation']").val(),
	        		"nativePlace": $("select[name='nativePlace']").val(),
	        		"politicalStatus": $("select[name='politicalStatus']").val(),
	        		"joinPartyDate": $("input[name='joinPartyDate']").val(),
	        		"conversionDate": $("input[name='conversionDate']").val(),
	        		"classId": $("input[name='classId']").val(),
	        		"identityType": $("select[name='identityType']").val(),
	        		"partyPost": $("select[name='partyPost']").val(),
	        		"contactPhone": $("input[name='contactPhone']").val(),
	        		"email": $("input[name='email']").val(),
	        		"applicationPath": $("#applicationPath").val(),
	        		"status": $("select[name='status']").val(),
	        		"remark": $("textarea[name='remark']").val()
	        	};
	        	
	        	// 发送JSON数据
	        	$.ajax({
                    url: prefix + "/edit",
                    type: "POST",
                    contentType: "application/json;charset=UTF-8",
                    data: JSON.stringify(data),
                    success: function(result) {
                        $.operate.successCallback(result);
                    },
                    error: function(xhr, status, error) {
                        $.modal.msgError("提交失败: " + (xhr.responseText || "未知错误"));
                    }
                });
	        }
	    }
		
		/* 关闭窗口 */
		function closeItem() {
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		}
	</script>
</body>
</html>